package com.silverhaze.diamond.client.ui.builders;

import com.silverhaze.diamond.client.Application;
import com.silverhaze.diamond.client.resources.ServiceResourceContainer;
import com.silverhaze.diamond.client.ui.frame.AbstractFrame;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Created by Ivan Babanin (10:13:45 01.06.2008)
 * This part of code is strictly confidential.
 * © Magnificent Software Inc.
 */
public class TrayIconBuilder {

    private static PopupMenu trayPopupMenu;

    public static void build() {
        if (System.getProperties().getProperty("os.name").indexOf(AbstractFrame.WIN_XP) != -1) {
            try {
                initTrayPopUp();
                SystemTray.getSystemTray().add(
                        new TrayIcon(ServiceResourceContainer.SERVICE.getImage(), "Service Center", trayPopupMenu));
            } catch (AWTException e) {
                throw new RuntimeException(e);
            }
        }
    }

    private static void initTrayPopUp() {
        trayPopupMenu = new PopupMenu();

        final MenuItem exitItem = new MenuItem("Exit");
        exitItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                Application.finish();
            }
        });

        trayPopupMenu.add(exitItem);
    }
}

